from __future__ import annotations
from dataclasses import dataclass, field
from datetime import datetime
from typing import List, Optional


@dataclass
class Progress:
    student_id: str
    course_id: str
    completed_assignments: int = 0
    total_assignments: int = 0
    current_average: float = 0.0
    grade_trend: List[float] = field(default_factory=list)
    last_updated: datetime = field(default_factory=datetime.now)

    def update(self, completed: int, total: int, new_average: float) -> None:
        self.completed_assignments = completed
        self.total_assignments = total
        self.current_average = float(new_average)
        self.grade_trend.append(self.current_average)
        self.last_updated = datetime.now()

    def calculate_completion_rate(self) -> float:
        if self.total_assignments == 0:
            return 0.0
        return (self.completed_assignments / self.total_assignments) * 100.0

    def get_current_grade(self) -> float:
        return self.current_average

    def get_grade_trend(self) -> List[float]:
        return list(self.grade_trend)

    def generate_report(self) -> dict:
        return {
            "student_id": self.student_id,
            "course_id": self.course_id,
            "completion_rate": self.calculate_completion_rate(),
            "current_average": self.current_average,
            "grade_trend": self.grade_trend,
            "last_updated": self.last_updated.isoformat(),
        }

    def predict_final_grade(self) -> float:
        # simple prediction: average of trend or current_average
        if not self.grade_trend:
            return self.current_average
        return sum(self.grade_trend) / len(self.grade_trend)
# Progress model